package example.mybatis.catalog.test;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.scaffold.catalog.entity.Catalog;

import example.mybatis.catalog.mapper.CatalogMapper;

@Repository
public class CatalogBatisDAO {
	@Autowired
	 private SqlSessionTemplate sqlSessionTemplate;
	
	public void save(Catalog catalog){
		CatalogMapper mapper = sqlSessionTemplate.getMapper(CatalogMapper.class);
		mapper.insert(catalog);
	}

	public Catalog findById(Long id){
		CatalogMapper mapper = sqlSessionTemplate.getMapper(CatalogMapper.class);
		return mapper.getCatalog(id);
	}
	 
	public List<Catalog> findAll(){
		CatalogMapper mapper = sqlSessionTemplate.getMapper(CatalogMapper.class);
		return mapper.selectCatalog();
	}
}
